<?php

namespace addons\yunfood\model;

use addons\yunfood\library\ModelTrait;
use app\common\model\User;
use think\Model;

/**
 * 菜品收藏模型
 */
class FoodLike extends Model
{
    use ModelTrait;

    // 表名,不含前缀
    protected $name = 'yunfood_food_like';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $updateTime = 'updated_at';
    protected $createTime = 'created_at';

    protected $resultSetType = 'collection';

    // 菜品数据
    public function foodData()
    {
        return $this->hasOne(Food::class, 'id', 'food_id');
    }

    // 用户数据
    public function userData()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }

    // 状态
    const STATUS_YES = 1;
    const STATUS_NO  = 2;

    public static function getStatusList()
    {
        return [self::STATUS_YES => __('已收藏'), self::STATUS_NO => __('已取消')];
    }

    public function getStatusTextAttr($value, $data)
    {
        $optionList = self::getStatusList();

        return $optionList[$data['status']] ?? $data['status'];
    }
}
